package com.deeper.customview.ui.c7.demo.c07d01;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.deeper.customview.BaseFragment;
import com.deeper.customview.R;

public class Chapter07Demo01Fragment extends BaseFragment {
    private TextView tv;
    private Button scrollBy;
    private Button scrollTo;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_chapter07_demo01, container, false);
        tv = root.findViewById(R.id.tv);
        scrollBy = root.findViewById(R.id.scrollby);
        scrollBy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv.scrollBy(-5, 0);
            }
        });
        scrollTo = root.findViewById(R.id.scrollto);
        scrollTo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int x = tv.getScrollX();
                int y = tv.getScrollY();
                tv.scrollTo(x - 5, y);
            }
        });
        return root;
    }
}
